package com.jeecms.wicool.manager.car.impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.car.CarOrderConfDao;
import com.jeecms.wicool.entity.car.CarOrderConf;
import com.jeecms.wicool.entity.shops.ShopInfo;
import com.jeecms.wicool.manager.car.CarOrderConfMng;
import com.jeecms.wicool.manager.shops.WiShopInfoMng;

@Service
@Transactional
public class CarOrderConfMngImpl implements CarOrderConfMng {
	
	private CarOrderConfDao dao;
	@Autowired
	public void setDao(CarOrderConfDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(Short orderType,String name ,int pageNo, int pageSize,CmsUser user) {
		Pagination page = dao.getPage(orderType, name ,pageNo, pageSize,user);
		return page;
	}
	@Override
	public CarOrderConf findById(Integer id) {
		CarOrderConf entity = dao.findById(id);
		return entity;
	}

	@Override
	public CarOrderConf update(CarOrderConf bean,Integer shopId) {
		ShopInfo shop = shopMng.findById(shopId);
		bean.setShop(shop);
		Updater<CarOrderConf> updater = new Updater<CarOrderConf>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	@Override
	public CarOrderConf save(CarOrderConf bean,Integer shopId) {
		ShopInfo shop = shopMng.findById(shopId);
		bean.setShop(shop);
		dao.save(bean);
		return bean;
	}

	@Override
	public CarOrderConf deleteById(Integer id) {
		CarOrderConf bean = dao.deleteById(id);
		return bean;
	}
	@Override
	public CarOrderConf[] deleteByIds(Integer[] ids) {
		CarOrderConf[] beans = new CarOrderConf[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public List<CarOrderConf> getAll(CmsUser user) {
		return dao.getAll(user);
	}
	@Autowired
	private WiShopInfoMng shopMng;
	
}